package linkerddriver

import (
	"gluenet/internal/agent/depend"
	"gluenet/internal/agent/driver"

	"github.com/spf13/viper"
)

type LinkerdDriver interface {
	Inject(namespace string) error

	Uninject(namespace string) error
}

func init() {
	depend.Provide(NewLinkerdConfig)
	depend.Provide(NewLinkerdDriver)
}

const (
	keyLinkerdConfig = driver.KeyDriverPerfix + `linkerd`
)

type LinkerdConfig struct {
	KubectlPath string `mapstructure:"kubectl_path"`
	LinkerdPath string `mapstructure:"linkerd_path"`
}

func NewLinkerdConfig(vp *viper.Viper) (*LinkerdConfig, error) {
	cfg := new(LinkerdConfig)
	if err := vp.UnmarshalKey(keyLinkerdConfig, cfg); err != nil {
		return nil, err
	}
	return cfg, nil
}

func NewLinkerdDriver(cfg *LinkerdConfig) (LinkerdDriver, error) {
	return NewSimpleLinkerdDriver(cfg)
}
